﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaiser.Modules.DC.Repositories;
using System.Collections;
using Kaiser.Models;
using Kaiser.Modules.DC.Models;

namespace Kaiser.Repositories.iBatis
{
    public class DCRepositories : IDCRepositories
    {
        private IBatisHepler IBatisHepler = null;
        public DCRepositories() {
            IBatisHepler = new BatisHepler("SQLMap.DC.config");
        }
        public int DeleteProductList(string ids)
        {
            Hashtable parms = new Hashtable();
            parms["ids"] = ids.Split(',');
            var result = IBatisHepler.ExcuteDelete("DeleteProductList", parms);
            return result;
        }

        public void InsertProduct(Modules.DC.Models.ProductInput model)
        {
            var result = IBatisHepler.ExcuteInsert("InsertProduct", model);
        }

        public void UpdateProduct(Modules.DC.Models.ProductInput model)
        {
            var result = IBatisHepler.ExcuteUpdate("UpdateProduct", model);
        }

        public Models.DataGrid<Modules.DC.Models.ProductInput> SearchProduct(Modules.DC.Models.DCSearch search, Models.PagingInfo pageinfo)
        {
            var result = new DataGrid<ProductInput>();
         
            int totalCount = 0;

            result.TableResult = IBatisHepler.ExcuteSelect("SearchProduct", search, pageinfo.Size, pageinfo.Index + 1, out totalCount);

            result.total = totalCount;

            return result;
        }

        public Models.DataGrid<Modules.DC.Models.OrderDetailInput> SearchOrderDetail(Modules.DC.Models.DCSearch search, Models.PagingInfo pageinfo)
        {
            var result = new DataGrid<OrderDetailInput>();
       
            int totalCount = 0;

            result.TableResult = IBatisHepler.ExcuteSelect("SearchOrderDetail", search, pageinfo.Size, pageinfo.Index + 1, out totalCount);

            result.total = totalCount;

            return result;
        }

        public int DeleteOrderList(string ids)
        {
            Hashtable parms = new Hashtable();
            parms["ids"] = ids.Split(',');
            var result = IBatisHepler.ExcuteDelete("DeleteOrderList", parms);
            return result;
        }

        public int DeleteOrderDetailList(string ids)
        {
            Hashtable parms = new Hashtable();
            parms["ids"] = ids.Split(',');
            var result = IBatisHepler.ExcuteDelete("DeleteOrderDetailList", parms);
            return result;
        }

        public void InsertOrderDetail(Modules.DC.Models.OrderDetailInput model)
        {
            var result = IBatisHepler.ExcuteInsert("InsertOrderDetail", model);
        }

        public void UpdateOrderDetail(Modules.DC.Models.OrderDetailInput model)
        {
            var result = IBatisHepler.ExcuteUpdate("UpdateOrderDetail", model);
        }

        public void InsertOrder(Modules.DC.Models.OrderInput model)
        {
            var result = IBatisHepler.ExcuteInsert("InsertOrder", model);
        }

        public void UpdateOrder(Modules.DC.Models.OrderInput model)
        {
            var result = IBatisHepler.ExcuteUpdate("UpdateOrder", model);
        }

        public Models.DataGrid<Modules.DC.Models.OrderStatisticsInput> OrderStatisticsList(Modules.DC.Models.DCSearch search, Models.PagingInfo pageinfo)
        {
            var result = new DataGrid<OrderStatisticsInput>();
            
            int totalCount = 0;

            result.TableResult = IBatisHepler.ExcuteSelect("OrderStatisticsList", search, pageinfo.Size, pageinfo.Index + 1, out totalCount);

            result.total = totalCount;

            return result;
        }

        public Models.DataGrid<Modules.DC.Models.OrderDetailStatistics> OrderDetailStatisticsList(Modules.DC.Models.DCSearch search, Models.PagingInfo pageinfo)
        {
            var result = new DataGrid<OrderDetailStatistics>();

            int totalCount = 0;

            result.TableResult = IBatisHepler.ExcuteSelect("OrderDetailStatisticsList", search, pageinfo.Size, pageinfo.Index + 1, out totalCount);

            result.total = totalCount;

            return result;
        }

        public Models.DataGrid<Modules.DC.Models.OrderInput> SearchOrder(Modules.DC.Models.DCSearch search, Models.PagingInfo pageinfo)
        {
            var result = new DataGrid<OrderInput>();
         
            int totalCount = 0;

            result.TableResult = IBatisHepler.ExcuteSelect("SearchOrder", search, pageinfo.Size, pageinfo.Index + 1, out totalCount);

            result.total = totalCount;

            return result;
        }
    }
}
